package com.pearsoned.apollo.actionscripts
{
    // imports needed for this AS Class
    import flash.display.Sprite;
    import flash.events.*;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.net.URLRequest;
    import mx.core.Application;

    public class BridgeSound extends Sprite {
        // declare a persistant, public variable to hold the sound effect's URL
        [Bindable] public var url:String;
        // declare a variable to hold a SoundChannel class
        public var song:SoundChannel;

        public function getSound():void {
            // declare a URLRequest variable that accepts a URL (url)
            var request:URLRequest = new URLRequest(url);
               // declare a variable to hold a soundFactory class
            var soundFactory:Sound = new Sound();
            /* add a COMPLETE event listener: Listens for the sound effect load completion; 
            completeHandler() function is called when the listener event occurs */
            soundFactory.addEventListener(Event.COMPLETE, completeHandler);
            /* add a ID3 event listener: Listens for ID3 availability; 
            id3Handler() function is called when the listener event occurs */
            soundFactory.addEventListener(Event.ID3, id3Handler);
            /* add a IO_ERROR event listener: Listens for any I/O errors; 
            ioErrorHandler() function is called if the listener event occurs */
            soundFactory.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
            /* add a PROGRESS event listener: Listens for the progression of the sound effect; 
            progressHandler() function is called when the listener event occurs */
            soundFactory.addEventListener(ProgressEvent.PROGRESS, progressHandler);
            // load the sound effect
            soundFactory.load(request);
            // play the sound effect
            song = soundFactory.play();
        }

        private function completeHandler(event:Event):void {
            trace("completeHandler: " + event);
        }

        private function id3Handler(event:Event):void {
            trace("id3Handler: " + event);
        }

        private function ioErrorHandler(event:Event):void {
            trace("ioErrorHandler: " + event);
        }

        private function progressHandler(event:ProgressEvent):void {
            trace("progressHandler: " + event);
        }

    }
}